package com.xyzq.cgate.core.condition.strategy;

import com.google.common.collect.Maps;
import com.xyzq.cgate.common.enums.MatchModeEnum;
import com.xyzq.cgate.core.condition.strategy.concrete.AndConditionMatchStrategy;
import com.xyzq.cgate.core.condition.strategy.concrete.OrConditionMatchStrategy;
import java.util.Map;
import java.util.Optional;

/**
 * @Description:
 * @author chenchen
 * @date 2019/6/20 8:55
 */
public class ConditionMatchStrategyFactory {

    final static Map<String, ConditionMatchStrategy> STRATEGY_MAP = Maps.newConcurrentMap();

    static {
        STRATEGY_MAP.put(MatchModeEnum.AND.getName(), new AndConditionMatchStrategy());
        STRATEGY_MAP.put(MatchModeEnum.OR.getName(), new OrConditionMatchStrategy());
    }

    public static ConditionMatchStrategy of(final String strategy) {
        return Optional.ofNullable(STRATEGY_MAP.get(strategy))
                .orElse(STRATEGY_MAP.get(MatchModeEnum.AND.getName()));
    }

}
